#include "mb.h"
#include <string.h>

#define MB_TCP_TID          0
#define MB_TCP_PID          2
#define MB_TCP_LEN          4
#define MB_TCP_UID          6
#define MB_TCP_FUNC         7

#define MB_TCP_PROTOCOL_ID  0   /* 0 = Modbus Protocol */


BOOL xMBTCPPortInit(MBTypeDef* psModbus, USHORT usTCPPort)
{
	return TRUE;
}

void vMBTCPPortClose(MBTypeDef* psModbus)
{

}

void vMBTCPPortDisable(MBTypeDef* psModbus)
{

}

BOOL xMBTCPPortRecv(MBTypeDef* psModbus, const UCHAR * pucFrame, USHORT usLength)
{
	USHORT usCount = sizeof(psModbus->ucBuf) - psModbus->usRcvBufferPos;
	usCount = usCount > usLength ? usLength : usCount;
	memcpy(psModbus->ucBuf, pucFrame, usCount);
	psModbus->usRcvBufferPos += usCount;
	xMBPortEventPost(psModbus, EV_FRAME_RECEIVED);
	return TRUE;
}

BOOL xMBTCPPortSend(MBTypeDef* psModbus, const UCHAR * pucFrame, USHORT usLength)
{
	return TRUE;
}
